package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.common.result.Result;
import com.example.entity.vo.CopmdVo;
import com.example.entity.yifei.Copmd;
import com.example.service.CopmdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-03-26
 */
@RestController
@RequestMapping("/api/copmd")
@Api(tags = "客户地址信息档相关接口")
public class CopmdController {

    @Autowired
    private CopmdService service;

    @ApiOperation("客户地址信息")
    @PostMapping("getAddressByCustomId")
    public Result<List<CopmdVo>> getAddressByUserId(@RequestParam String customId) {
        LambdaQueryWrapper<Copmd> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Copmd::getMd001, customId);
        List<Copmd> list = service.list(wrapper);
        List<CopmdVo> res = new ArrayList<>();
        for(Copmd c : list) {
            CopmdVo copmdVo = new CopmdVo();
            BeanUtils.copyProperties(c, copmdVo);
            res.add(copmdVo);
        }
        return Result.success(res);
    }

    @ApiOperation("查询所有客户地址")
    @PostMapping("getAllAddress")
    public Result<List<CopmdVo>> getAllAddress() {
        List<Copmd> list = service.list();
        List<CopmdVo> res = new ArrayList<>();
        for(Copmd c : list) {
            CopmdVo copmdVo = new CopmdVo();
            BeanUtils.copyProperties(c, copmdVo);
            res.add(copmdVo);
        }
        return Result.success(res);
    }

}
